﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shipwire.Messages;

namespace Shipwire.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class InventoryTests
    {
        [TestMethod]
        public void Test_GetInventoryDetails()
        {
            IShipwireService service = TestShipwireAccount.CreateTestService();
            var result = service.GetInventoryDetails();

            Assert.AreEqual("Test", result.Status);
            Assert.IsNull(result.ErrorMessage);

            Assert.AreEqual<int>(2, result.TotalProducts);
            Assert.AreEqual<int>(2, result.Products.Length);

            ValidateTestProduct0(result.Products[0]);
            ValidateTestProduct1(result.Products[1]);
        }

        //[TestMethod]
        //public void Test_GetInventoryDetails_ForTestProduct()
        //{
        //    Assert.Fail("Currently Shipwire does not respond properly to requests for a specific product code.");
        //    IShipwireService service = TestShipwireAccount.CreateTestService();
        //    var result = service.GetInventoryDetails("GD201-500");

        //    Assert.AreEqual("Test", result.Status);
        //    Assert.IsNull(result.ErrorMessage);

        //    Assert.AreEqual<int>(1, result.TotalProducts);
        //    Assert.AreEqual<int>(1, result.Products.Length);

        //    ValidateTestProduct1(result.Products[0]);
        //}

        private static void ValidateTestProduct0(InventoryUpdateResponseProduct product)
        {
            Assert.AreEqual<DateTime>(DateTime.Parse("19/01/2012"), product.AvailableDate);
            Assert.AreEqual<string>("GD802-024", product.Code);
            Assert.AreEqual<int>(14, product.Quantity);
            Assert.AreEqual<int>(14, product.Good);
            Assert.AreEqual<int>(300, product.Pending);
            Assert.AreEqual<int>(0, product.BackOrdered);
            Assert.AreEqual<int>(15, product.Reserved);
            Assert.AreEqual<int>(7, product.Shipping);
            Assert.AreEqual<int>(7013, product.Shipped);
            Assert.AreEqual<int>(0, product.Consuming);
            Assert.AreEqual<int>(0, product.Creating);
            Assert.AreEqual<int>(0, product.Created);
            Assert.AreEqual<int>(13, product.ShippedLastDay);
            Assert.AreEqual<int>(84, product.ShippedLastWeek);
            Assert.AreEqual<int>(401, product.ShippedLast4Weeks);
            Assert.AreEqual<int>(15, product.OrderedLastDay);
            Assert.AreEqual<int>(99, product.OrderedLastWeek);
            Assert.AreEqual<int>(416, product.OrderedLast4Weeks);
        }
        private static void ValidateTestProduct1(InventoryUpdateResponseProduct product)
        {
            Assert.AreEqual<DateTime>(DateTime.Parse("21/02/2012"), product.AvailableDate);
            Assert.AreEqual<string>("GD201-500", product.Code);
            Assert.AreEqual<int>(32, product.Quantity);
            Assert.AreEqual<int>(32, product.Good);
            Assert.AreEqual<int>(500, product.Pending);
            Assert.AreEqual<int>(0, product.BackOrdered);
            Assert.AreEqual<int>(17, product.Reserved);
            Assert.AreEqual<int>(0, product.Shipping);
            Assert.AreEqual<int>(1997, product.Shipped);
            Assert.AreEqual<int>(0, product.Consuming);
            Assert.AreEqual<int>(0, product.Creating);
            Assert.AreEqual<int>(0, product.Created);
            Assert.AreEqual<int>(11, product.ShippedLastDay);
            Assert.AreEqual<int>(74, product.ShippedLastWeek);
            Assert.AreEqual<int>(221, product.ShippedLast4Weeks);
            Assert.AreEqual<int>(19, product.OrderedLastDay);
            Assert.AreEqual<int>(90, product.OrderedLastWeek);
            Assert.AreEqual<int>(242, product.OrderedLast4Weeks);
        }
    }
}
